/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.util.benchmark.test;
import flash.geom.Point;
import hapi.math.Vector2D;
import hapi.util.benchmark.BenchmarkRunner;
import hapi.util.benchmark.FunctionBenchmark;
import haxe.unit.TestRunner;

typedef XY = {
	var x:Float;
	var y:Float;
}

class StrongTyping {
	
	static inline var ITERATIONS_NUM = 100000;

	public static function perform(runner:BenchmarkRunner) {
		var f1 = function() {
			for( i in 0...ITERATIONS_NUM ) {
				var pt = new Point(i,i/3);
				pt.x += i;
				pt.y -= i/2;
			}
		}
		var f2 = function() {
			for( i in 0...ITERATIONS_NUM ) {
				var pt:Dynamic = new Vector2D(i,i/3);
				pt.x += i;
				pt.y -= i/2;
			}
		}
		var f3 = function() {
			for( i in 0...ITERATIONS_NUM ) {
				var pt = {x:i, y:i/3};
				pt.x += i;
				pt.y -= i/2;
			}
		}
		var f4 = function() {
			for( i in 0...ITERATIONS_NUM ) {
				var pt:XY = new Point(i,i/3);
				pt.x += i;
				pt.y -= i/2;
			}
		}
		runner.add(new FunctionBenchmark("strong", f1, 1));
		runner.add(new FunctionBenchmark("dynamic", f2, 1));
		runner.add(new FunctionBenchmark("typedef", f3, 1));
		runner.add(new FunctionBenchmark("typedef-point", f4, 1));
	}
	
}